package Demo.菜鸟驿站;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Job extends JFrame {
    Goods[] goods= new Goods[50];
    private JLabel j1;
    private JPanel p1, p2;
    private JTextField txtInput;
    private JButton jbutton;
    int a;

    public Job(){
        goods[0]=new Goods(1,"保淞","123","2022.5.31","","","王保淞");
        this.setTitle("工作面板");
        this.setBounds(300,100,300,200);
        //关闭窗口
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new GridLayout(6, 1, 5, 5));
        j1 = new JLabel("欢迎使用工作系统\n" + "1.入库\n" + "2.客户取货\n" + "3.查看未收货订单\n"
                + "4.按取货码查询订单\n" + "5.按姓名查询订单\n"+"6.修改密码\n"+"7.安全退出\n");
        p1 = new JPanel();
        p1.add(j1);
        jbutton = new JButton("确认");
        txtInput = new JTextField(20);
        p2 = new JPanel();
        p2.add(txtInput, BorderLayout.WEST);
        p2.add(jbutton, BorderLayout.EAST);
        this.add(p1);
        this.add(p2, BorderLayout.SOUTH);
        jbutton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                a = Integer.parseInt(txtInput.getText());
                switch (a) {
                    case 1:
                       add();
                        break;
                    case 2:
                        break;
                    case 3:
                        lista();
                        break;
                    case 4:
                        break;
                    case 5:
                        break;
                    case 6:
                        break;
                    case 7:
                        System.exit(0);
                        break;
                }
            }
        });
        this.setVisible(true);
    }

    private void add() {
        JTextField txtInput,txtInput1;
        JButton jbutton;
        JPanel p1, p2;

        //设置窗口标题
        this.setTitle("员工管理窗口");
        //设置位置和尺寸
        this.setBounds(300, 100, 300, 600);
        //关闭窗口
        this.setLayout(new GridLayout(10, 1, 10, 10));
        JOptionPane.showMessageDialog(null, "请输入时间");
        jbutton = new JButton("确认");
        p1 = new JPanel();
        txtInput = new JTextField(20);
        p1.add(txtInput, BorderLayout.WEST);
        p1.add(jbutton, BorderLayout.EAST);
        this.add(p1, BorderLayout.SOUTH);
        jbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int index = -1;
                for (int i = 0; i < goods.length; i++) {
                    if (goods[i] == null) {
                        index = i;
                        break;
                    }
                }
                if (index != -1) {
                    goods[index].number = index + 1;
                    goods[index].phone = " ";
                    goods[index].time = txtInput.getText();
                    goods[index].Staff = "员工";
                    JOptionPane.showMessageDialog(null, "添加成功");
                } else {
                    JOptionPane.showMessageDialog(null, "快递已满");
                }
            }
        });
        this.setVisible(true);
    }


    private void lista() {
        JLabel a;
        //设置窗口标题
        this.setTitle("快递管理窗口");
        //设置位置和尺寸
        this.setBounds(300, 100, 300, 600);
        //关闭窗口
        this.setLayout(new GridLayout(10, 1, 10, 10));

        for (int i = 0; i < goods.length; i++) {
            if (goods[i] != null) {
                a = new JLabel(goods[i].number+" "+goods[i].name+" "+goods[i].time+" "+goods[i].phone+" "+goods[i].Staff);
                this.add(a);
                break;
            } else {
                JOptionPane.showMessageDialog(null,"没有快递");
                break;
            }
        }
    }


}